package com.hd.crdao.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.bean.GpsDetailBean;
import com.hd.crdao.wrapper.GpsDrawable;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyGpsLocationDetailAdapter extends RecyclerView.Adapter<MyGpsLocationDetailAdapter.ViewHolder> {

    private List<GpsDetailBean.ListGpsEventBean> list;
    private OnItemClickListener mOnItemClickLister;

    public MyGpsLocationDetailAdapter(List<GpsDetailBean.ListGpsEventBean> list) {
        this.list = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gpslocationdetail, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        GpsDetailBean.ListGpsEventBean listGpsEventBean = list.get(position);

        holder.mLeftPosition.setText((position + 1) + "");
        holder.mCreateDate.setText(listGpsEventBean.getCreateDate());
        holder.mGeCuradd.setText(listGpsEventBean.getGeCuradd());
        //2、	已拔出
        //3、	已超时
        // 5、	超出范围
        switch (listGpsEventBean.getGeEvent()) {
            case 2:
                holder.mGeEvent.setText("已拔出");

                break;
            case 3:
                holder.mGeEvent.setText("已超时");
                break;
            case 5:
                holder.mGeEvent.setText("超出范围");
                break;
        }
        holder.mLeftPosition.setBackgroundResource(GpsDrawable.getGpsDrawable(listGpsEventBean.getGeEvent()));
        if (!TextUtils.isEmpty(listGpsEventBean.getGeEventnote())) {
            holder.mNoteLayout.setVisibility(View.VISIBLE);
            holder.mNoteDesc.setText("客服人员:"+listGpsEventBean.getNoteName()+"\t\t"+listGpsEventBean.getNoteDate());
           // holder.mNoteDate.setText(listGpsEventBean.getNoteDate());
          //  holder.mNoteName.setText(listGpsEventBean.getNoteName());
            holder.mGeEventnote.setText(listGpsEventBean.getGeEventnote());
        } else {
            holder.mNoteLayout.setVisibility(View.GONE);
        }


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickLister != null) {
                    mOnItemClickLister.onItemClick(v, holder.getAdapterPosition());
                }
            }
        });
    }


    @Override
    public int getItemCount() {
        if (list != null) {
            return list.size();
        }
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.notelayout)
        LinearLayout mNoteLayout;
        @BindView(R.id.left_position)
        TextView mLeftPosition;
        @BindView(R.id.geEvent)
        TextView mGeEvent;
        @BindView(R.id.geCuradd)
        TextView mGeCuradd;
        @BindView(R.id.createDate)
        TextView mCreateDate;
        @BindView(R.id.geEventnote)
        TextView mGeEventnote;
        /*@BindView(R.id.noteName)
        TextView mNoteName;
        @BindView(R.id.noteDate)
        TextView mNoteDate;*/
        @BindView(R.id.noteDesc)
        TextView mNoteDesc;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public void setOnItemClickLister(OnItemClickListener onItemClickLister) {
        if (onItemClickLister != null) {
            this.mOnItemClickLister = onItemClickLister;
        }

    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }


}